package no.ntnu.idi.evaluering;

import java.io.File;
import java.util.ArrayList;

import no.ntnu.idi.deid.documentunits.Document;
import no.ntnu.idi.deid.documentunits.Token;
import no.ntnu.idi.deid.documentunits.TokenIterator;

public class EvaluationList extends ArrayList<EvaluationEntity> {

	private static final long serialVersionUID = 1L;
	
	private String mName = "";
	
	public EvaluationList(Document document) {
		super();
		setName(document.getName());
		addDocument(document);
		if(mName.equals("")) {
			System.err.println("EvaluationList: mNavn kan ikke være tom, feil for dokument"+document.getName());
		}
	}
	
	public EvaluationList(File file) {
		super();
		setName(file.getName());
		addEvaluationFile(file);
		if(mName.equals("")) {
			System.err.println("EvaluationList: mNavn kan ikke være tom, feil for fil"+file.getName());
		}
	}
	
	public EvaluationList(String name) {
		super();
		setName(name);
	}
	
	
	private void addDocument(Document document) {
		TokenIterator i = document.getTokenIterator();
		while(i.hasNext()) {
			Token token = i.next();
		add(new EvaluationEntity(token.getOrginal(), token.isSensitiv()));
		}
	}
	
	public void addCorpusFromfolder(File folder) {
		if(folder.isDirectory()) {
			File[] filesFolder = folder.listFiles();
			for(File f: filesFolder) {
				addEvaluationFile(f);
			}
		}
	}
	
	public void addEvaluationFile(File file) {
		addAll(EvaluationFile.readFile(file));
	}

	public String getName() {
		return mName;
	}

	private void setName(String name) {
		this.mName = name;
	}
	
	public EvaluationScore evaluateAgainst(EvaluationList goldStandardList) {
		return new EvaluationScore(goldStandardList, this);
	}
}
